package com.huike.web.controller.report;


import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.StringUtils;
import com.huike.report.domain.vo.IndexBaseInfoVO;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.security.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }
    /**
     * 首页--今日简报数据统计
     * @param
     * @param
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){
        //时间格式
        DateTimeFormatter time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //获取当前的时间
        LocalDateTime nowTime= LocalDateTime.now();
        //获取零点的时间
        LocalDateTime start_time = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        String endTime = time.format(nowTime);
        String startTime = time.format(start_time);
        IndexTodayInfoVO todayInfo = reportService.getTodayInfo(startTime, endTime);
        return AjaxResult.success(reportService.getTodayInfo(startTime,endTime));
    }

    /**
     * 首页--今日简报数据统计
     * 接口名 /index/getTodoInfo
     * @param
     * @param
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
       return AjaxResult.success(reportService.getTodoInfo(beginCreateTime,endCreateTime));
    }

    /**
     * 首页--龙虎榜线索转商机
     * 接口名 /index/getTodoInfo
     * @param
     * @param
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.salesStatistic(beginCreateTime,endCreateTime));
    }
    /**
     * 首页--龙虎榜线索转商机
     * 接口名 /index/getTodoInfo
     * @param
     * @param
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                               @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.businessChangeStatistics(beginCreateTime,endCreateTime));
    }
}